//
//  RTLBatchRequest.h
//  RTLNetWorking
//
//  Created by 林波 on 16/7/11.
//  Copyright © 2016年 linbo1. All rights reserved.

//  网络框架（批量请求数据）

#import <Foundation/Foundation.h>
#import "RTLBaseRequest.h"
@class RTLBatchRequest;

// block 定义成功、失败、取消
typedef void(^RTLBatchRequestSuccessCallback)(RTLBatchRequest *batchRequest, NSMutableArray *responseObjectArray);
typedef void(^RTLBatchRequestFailureCallback)(RTLBatchRequest *batchRequest, __kindof RTLBaseRequest *request, NSError *error);
typedef void(^RTLBatchRequestCancelCallback)(RTLBatchRequest *batchRequest);


@interface RTLBatchRequest : NSObject


// 但前请求的数组
@property (nonatomic, strong, readonly) NSArray *requests;

// 当出现错误的时候取消当前的请求
@property (nonatomic, assign) BOOL cancelWhenErrorOccur;


@property (nonatomic, strong) dispatch_queue_t completionQueue;


// 初始化
- (instancetype)initWithRequests:(NSArray<RTLBaseRequest *>*) requests;

// 添加请求
- (void)addAccessory:(id<RTLRequestAccessory>)accessory;




@property (nonatomic, copy) RTLBatchRequestSuccessCallback successCallback;
@property (nonatomic, copy) RTLBatchRequestFailureCallback failureCallback;

// 设置成功、失败的回调（这个方法没有开始请求如果要开始请求调用下面 start 方法）
- (void)setSuccesssCallback:(RTLBatchRequestSuccessCallback)success failureCallback:(RTLBatchRequestFailureCallback)failure;


// 开始
- (void)start;

// 设置成功、失败的回调（这里开始请求）
- (void)startBatchReqeustSuccessCallback:(RTLBatchRequestSuccessCallback)success failureCallback:(RTLBatchRequestFailureCallback)failure;


@property (nonatomic, copy) RTLBatchRequestCancelCallback cancelCallback;

//取消
- (void)cancel;

//取消批量请求回调(具体是哪个)
- (void)cancelWithCallback:(RTLBatchRequestCancelCallback)cancel;



@end


@interface RTLBatchRequestManager : NSObject

// 单例
+ (instancetype)sharedManager;

// 加入批量请求接口
- (void)addBatchRequest:(RTLBatchRequest *)batchRequest;

// 移除批量请求接口
- (void)removeBatchRequest:(RTLBatchRequest *)batchRequest;

@end

